@extends('shop::layouts.master')
@section('title')
    {{$title}}
@endsection
<style>
    .close{
        position: absolute; top: -5px; right: -3px; background-color: #FFFFFF; border-radius: 50%; color: #FFF; padding-top: 1px; opacity:0.1;
    }
    .type-list:hover .close
    {
        opacity:1; background-color: red;
    }
    #makeDate .layui-input-inline{width: 120px}
    .layui-upload-img {
        width: 150px; height: 100px;
    }
</style>
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">

                <input type="hidden" name="id" value="{{$detail['id']}}">
                <input type="hidden" name="cate" value="{{$detail['cate']}}">
                <div class="layui-form-item"> </div>

                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        @if( $detail['cate'] == 3 )
                            <span class="x-red">*</span>机构名称</label>
                        @else
                            <span class="x-red">*</span>检测机构名称</label>
                        @endif
                    <div class="layui-input-inline" style="width: 588px;">
                        <input type="text" name="name" this-id="{{$detail['id']}}" value="{{$detail['name']}}" lay-verify="required" autocomplete="off" class="layui-input edit-shop">
                    </div>
                </div>
                @if( $detail['cate'] != 3 )
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>检测机构类型</label>
                    <div class="layui-input-inline" style="width: 588px;">
                        <select name="type" lay-filter="province">
                            <option value="">请选择</option>
                            @if($type)
                            @foreach($type as $k => $v)
                                <option value="{{$v['id']}}" @if($detail['type']==$v['id']) selected @endif>{{$v['title']}}</option>
                            @endforeach
                            @endif
                        </select>
                    </div>
                </div>
                @endif
                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        <span class="x-red">*</span>联系方式</label>
                    <div class="layui-input-inline" style="width: 588px;">
                        <input type="text" name="phone" this-id="{{$detail['id']}}" value="{{$detail['phone']}}" lay-verify="phone" autocomplete="off" class="layui-input edit-shop">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        <span class="x-red">*</span>公司log</label>
                    <div class="layui-input-inline">
                        @if($detail['logo']['full_src'])
                            <img class="layui-upload-img upload_img" src="{{$detail['logo']['full_src']}}">
                        @else
                            <img class="layui-upload-img upload_img" src="admin/images/upimg.png">
                        @endif
                        <input type="hidden" name="logo" value="" lay-verify="pic_log" id="img_url">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        <span class="x-red">*</span>所在城市</label>
                    <div class="layui-input-inline">
                        <select name="province" lay-verify="required" lay-filter="province">
                            <option value="">请选择</option>
                            @foreach($province as $p => $pr)
                                <option value="{{$p}}" @if($detail['province']==$p) selected @endif>{{$pr}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="city" lay-verify="required" lay-filter="city" id="city">
                            <option value="">请选择</option>
                            @foreach($city as $c => $ci)
                                <option value="{{$c}}" @if($detail['city']==$c) selected @endif>{{$ci}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="area" lay-verify="required" lay-filter="area" id="area">
                            <option value="">请选择</option>
                            @foreach($area as $a => $ar)
                                <option value="{{$a}}" @if($detail['area']==$a) selected @endif>{{$ar}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        <span class="x-red">*</span>详细地址</label>
                    <div class="layui-input-inline" style="width: 588px;">
                        <input type="text" name="address" value="{{$detail['address']}}" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label for="L_alias" class="layui-form-label">
                            <span class="x-red">*</span>经纬度</label>
                        <div class="layui-input-inline" >
                            <input type="text" name="longitude" value="{{$detail['longitude']}}" id="longitude" lay-verify="required" class="layui-input">
                        </div>
                        <div class="layui-input-inline" >
                            <input type="text" name="latitude" value="{{$detail['latitude']}}" id="latitude" lay-verify="required" class="layui-input">
                        </div>
                        <a class="layui-btn layui-btn-primary layui-btn-xs" id="parentIframe"> 拾取坐标 </a>
                    </div>
                </div>
                @if( $detail['cate'] != 3 )
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label for="L_alias" class="layui-form-label">
                            <span class="x-red">*</span>服务类型</label>
                        @if($detail['service_type'])
                            <input type="hidden" value="1" class="img_num" lay-verify="img_num">
                            @foreach($detail['service_type'] as $st => $ste)
                            <div class="layui-input-inline type-list">
                                <input type="text" name="service[{{$st}}][title]" value="{{$ste['title']}}" lay-verify="required" class="layui-input imgNum">
                                <i class="layui-icon close">ဆ</i>
                            </div>
                            @endforeach
                        @else
                            <input type="hidden" value="1" class="img_num" lay-verify="img_num">
                            <div class="layui-input-inline type-list">
                                <input type="text" name="service[0][title]" value="" lay-verify="required" class="layui-input imgNum">
                            </div>
                        @endif

                        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm add_type" da-in="0"><i class="layui-icon"></i></button>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        <span class="x-red">*</span>年检费用</label>
                    <div class="layui-input-block" style="width: 60%">
                        {!! baidu_ueditor($detail['expenses'], 'expenses') !!}
                    </div>
                </div>
                @else
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label for="L_alias" class="layui-form-label">
                                <span class="x-red">*</span>营业时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="start_time" value="<?php echo e($detail['start_time']); ?>" id="start" placeholder="上班时间" lay-verify="required" readonly="readonly" class="layui-input">
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" name="end_time" value="<?php echo e($detail['end_time']); ?>"  id="end" placeholder="下班时间" lay-verify="required" readonly="readonly" class="layui-input">
                            </div>
                        </div>
                    </div>


                @endif
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn layui-btn-normal" lay-filter="add" lay-submit="">提交</button>
                </div>
            </form>
        </div>
    </div>

@endsection

@section('tab_js')
    @include('shop::author.this_js')
    <script>
        layui.use(['form', 'layer', 'jquery','laydate'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer,
                laydate = layui.laydate,
                upload = layui.upload;
                //执行一个laydate实例
                lay('.day').each(function () {
                    laydate.render({
                        elem: this,
                        trigger: 'click'
                    });
                });

            laydate.render({
                elem: '#start'
                ,type: 'time'
                ,done: function(value){
                    var end = $('#end').val();
                    if (end && value > end) {
                        layer.msg('上班时间必须小于下班时间');
                        $('#start').val('');
                    };
                }
            });
            laydate.render({
                elem: '#end'
                ,type: 'time'
                ,done: function(value){
                    var start = $('#start').val();
                    if (start && value < start) {
                        layer.msg('下班时间必须大于上班时间');
                        $('#end').val('');
                    };
                }
            });


            form.verify({
                img_num : function(value) {
                    if (value <= 0) {
                        return '请添加服务类型';
                    }
                },
            });
            form.render('select');
            //监听提交
            form.on('submit(add)', function (data) {
                $.ajax({
                    url: js_url('shop-author-checkUpdate'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg(result.msg, {time: 600, icon: 6});
                        } else {
                            layer.msg(result.msg, {time: 600, icon: 5});
                        }
                    }
                });
                return false;

            });

        });
    </script>
@endsection




